"use strict";

/**
 * @ngdoc function
 * @name jgappApp.controller:SearchDetailCtrl
 * @description
 * # SearchDetailCtrl
 * Controller of the jgappApp
 */
angular
  .module("jgappApp")
  .controller(
    "SearchDetailCtrl",
    function ($scope, DataService, openApi, $rootScope, FileService, OpenFile, Util, $timeout) {
      var routeConfig = Util.getRouteConfig();
      $scope.formKey = routeConfig.formKey;
      var setDetailSeen = function (processInstanceId) {
        var param = {};
        param.noloader = true;
        param.processInstanceId = processInstanceId;
        DataService.getData(openApi.publicDoc, param).then(function (data) { });
      };
      var getDetail = function () {
        DataService.getData(
          openApi.ip + routeConfig.url,
          routeConfig.data
        ).then(function (data) {
          if (data) {
            $scope.TaskReview = {};
            $scope.TaskReview.result = data;
            $scope.process_id = data.processInstanceId;
            if ($scope.formKey == "Chief_PublicDoc") {
              setDetailSeen(data.processInstanceId);
            }
          }
        });
      };
      $scope.hrefLink = function (href) {
        // ios & android are opened in the different way
        OpenFile.showfile(href)
      };
      $scope.goDetail = function (fileData) {
        if (Util.isImg(fileData)) {
          FileService.showfile(fileData);
        } else if (Util.isFile(fileData)) {
          OpenFile.open(fileData);
        } else {
          Util.Toast("移动端不支持预览");
        }
      };

      var init = function () {
        $timeout(
          function () {
            Util.insertRelList({
              scope: $scope
            });
          },
          500
        );

        getDetail();
        $rootScope.nofooter = true;
        
      };
      init();
    }
  );
